<?php

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
error_reporting(E_ERROR | E_PARSE);

//error_reporting(E_ALL);
//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival['t'], "t", "json");
		
	cgi::both($g_cgival['callback'], "callback", "");
	$g_cgival['callback'] = string::un_html(string::un_script_code($g_cgival['callback']));
	
	cgi::both($g_cgival['pscreen'], "pscreen", 1);
	
	cgi::both($g_cgival['topic_id'], "topic_id", 0);
	
	$g_cgival['topic_id'] = intval($g_cgival['topic_id']);
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	$topic_id = $g_cgival['topic_id'];
	
	
	$db_mblog_cron_content = new db_mblog_cron_content();
	$list = $db_mblog_cron_content->get_mblog_list_by_test($g_cgival['pscreen']);
	
	

	
	$start_value = "";
	foreach($list as $value)
	{
	
		if($start_value < $value["create_time"])
		{
			$start_value = $value["create_time"];
		} 
		$data = <<<EOF
		<li>
<div class="pretty-pic" style="width:{$value["pic_width_pubu"]}px; height:{$value["pic_height_pubu"]}px">
<img width={$value["pic_width_pubu"]} height={$value["pic_height_pubu"]} src="{$value["pic"]}">
</div>

<dl class="clear">
								<dt class="fl"><a target="_blank" href="/u/2733839507"><img width="30" height="30" alt="Jerusalem-Dr" src="http://tp4.sinaimg.cn/{$value["create_uid"]}/50/5634717469/0" class="name-card" uid="2733839507"></a> <a class="fr" target="_blank" href="http://food.henan.sina.com.cn/explore/detail-2829529.html">06/18 16:40</a><a target="_blank" class="name-card" uid="2733839507" href="/u/2733839507">{$value["create_nickname"]}</a></dt>
								<dd>
									<p></p> 
									<p>{$value["content"]}</p>
								</dd>
							</dl>
</li>
EOF;
	$div_list[] = $data;
		
	}
	if(!$div_list)
	{
		$div_list = array();
	}
	$g_show["data"] = $div_list;
	$g_show["start_value"] = $start_value;
	
	
}
try {
	
	check_cgi_pro();
	get_data();
	$g_show["error"] = 0;
	$g_show["errmsg"] = "";
	
	
} 
catch (Exception $e) 
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
	
}
show_pro();

exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	if ($g_cgival['t'] == "serialize")
	{
		echo serialize($g_show);
	}
	elseif ($g_cgival['t'] == "json")
	{
		echo output::json("json", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "jsonp")
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "perl")
	{
		$string = php_to_perl::php_array_to_perl_hash($g_show);
		$string = mb_convert_encoding($string, "GBK", "UTF-8");
		echo $string;
	}
	elseif($g_cgival['t'] == "iframe")
	{
		header("location:{$g_cgival['link']}");
	}
	else
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
}
?>
